package com.atguigu.democustomer230315.service.impl;

import com.atguigu.democustomer230315.bean.Customer;
import com.atguigu.democustomer230315.mapper.CustomerMapper;
import com.atguigu.democustomer230315.service.CustomerService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DS("demo")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper,Customer> implements CustomerService {
    @Autowired
    CustomerMapper customerMapper;

    @Override
    public String customerByName(String name) {
        System.out.println("Service："+name);
//        Customer result = customerMapper.selectCustomerByName(name);
//        String sql = "select * from customer where name='" + name + "'";
//        Customer result = customerMapper.selectCustomerByNameNoSQl(sql);
        //Mybatisplus提供的方法查询数据库
        Customer result = customerMapper.selectOne(new QueryWrapper<Customer>().eq("name", name));
        return result.toString();
    }

    @Override
    public void saveCustomerWithNameAndAge(String name, Integer age) {
        customerMapper.insertCustomerByNameAndAge(name,age);
    }

    @Override
    @DS("test")
    public void saveCustomerWithObj(Customer customer) {
        customerMapper.insertCustomerByObj(customer);
    }
}
